package com.ruoyi.system.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.MapPark;
import com.ruoyi.system.domain.SysUploadFile;
import com.ruoyi.system.domain.UploadFileType;
import com.ruoyi.system.domain.vo.MapParkVo;
import com.ruoyi.system.mapper.MapParkMapper;
import com.ruoyi.system.mapper.SysFileMapper;
import com.ruoyi.system.service.IMapParkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 产业园区Service业务层处理
 *
 * @author cqust_icc
 * @date 2022-06-25
 */
@Service
public class MapParkServiceImpl implements IMapParkService {
    @Autowired
    private MapParkMapper mapParkMapper;

    @Autowired
    private SysFileMapper sysFileMapper;

    /**
     * 查询产业园区
     *
     * @param id 产业园区主键
     * @return 产业园区
     */
    @Override
    public MapParkVo selectMapParkById(Long id) {
        List<SysUploadFile> bannerFile = sysFileMapper.selectSysFileList(new SysUploadFile(UploadFileType.PARK_BANNER, id));
        List<SysUploadFile> imageFile = sysFileMapper.selectSysFileList(new SysUploadFile(UploadFileType.PARK_PICTURE, id));
        List<SysUploadFile> modelFile = sysFileMapper.selectSysFileList(new SysUploadFile(UploadFileType.PARK_MODEL, id));
        MapParkVo mapPark = mapParkMapper.selectMapParkById(id);

        if (imageFile != null) {
            mapPark.setImageFile(imageFile.stream().map(v -> new SysUploadFile.SysFileVo(v.getFilePath(), v.getFileId())).collect(Collectors.toList()));
        }

        if (mapPark != null) {
            mapPark.setBannerFile(bannerFile.stream().map(v -> new SysUploadFile.SysFileVo(v.getFilePath(), v.getFileId())).collect(Collectors.toList()));
        }
        if (modelFile != null) {
            mapPark.setModelFile(modelFile.stream().map(v -> new SysUploadFile.SysFileVo(v.getFilePath(), v.getFileId())).collect(Collectors.toList()));
        }
        return mapPark;
    }

    /**
     * 查询产业园区列表
     *
     * @param mapPark 产业园区
     * @return 产业园区
     */
    @Override
    public List<MapPark> selectMapParkList(MapPark mapPark) {
        return mapParkMapper.selectMapParkList(mapPark);
    }

    /**
     * 新增产业园区
     *
     * @param mapPark 产业园区
     * @return 结果
     */
    @Override
    public int insertMapPark(MapPark mapPark) {
        mapPark.setCreateTime(DateUtils.getNowDate());
        return mapParkMapper.insertMapPark(mapPark);
    }

    /**
     * 修改产业园区
     *
     * @param mapPark 产业园区
     * @return 结果
     */
    @Override
    public int updateMapPark(MapPark mapPark) {
        return mapParkMapper.updateMapPark(mapPark);
    }

    /**
     * 批量删除产业园区
     *
     * @param ids 需要删除的产业园区主键
     * @return 结果
     */
    @Override
    public int deleteMapParkByIds(Long[] ids) {
        return mapParkMapper.deleteMapParkByIds(ids);
    }

    /**
     * 删除产业园区信息
     *
     * @param id 产业园区主键
     * @return 结果
     */
    @Override
    public int deleteMapParkById(Long id) {
        return mapParkMapper.deleteMapParkById(id);
    }
}
